
#ifndef EVENTMEMORYTABLE_H_
#define EVENTMEMORYTABLE_H_


#include "../../Packets/BackSubPkt.h"
#include "../../Packets/PubPkt.h"
#include "../../Common/TimeMs.h"
#include <boost/unordered_map.hpp>
#include <string>
#include <queue>
#include "../../Memory/MemoryWrapper.h"
#include <iostream>
#include "MemoryTable.h"
#include "../../Common/Consts.h"
#include "OCMMemoryTable.h"


using namespace std;

class ClusterSelector {

	typedef struct {
		std::string name;
		float start;
		float end;
	} Cluster;

public:

	ClusterSelector(float* points, int n);

	virtual ~ClusterSelector();

	std::string getClusterName(float value);

private:

	int clustersNumber;
	Cluster *clusters;
	float MINUS_INF, PLUS_INF;
};



class EventMemoryTable : public OCMMemoryTable {

public:

	EventMemoryTable(int parNumMaxSlot, MemoryWrapper* parMemory, float* clusterDelimiters, int numDelimiters, float parLastThreshold);

	virtual ~EventMemoryTable();

	void computeInsertion(PubPkt *pkt, int ns, float ws, float lastPercentage);

	void computeExtraction(BackSubPkt *pkt, std::set<PubPkt*> &resultSet);

private:

	boost::unordered_map<std::string, std::priority_queue<std::pair<timestamp_t, key_t>, std::vector<std::pair<timestamp_t, key_t> >, Comparison > > clustersMap;
	boost::unordered_map<key_t, std::pair<int, float> > keyToParametersMap;
	boost::unordered_map<key_t, bool> keyToResettableMap;

	int numMaxSlot;
	int numUsedSlot;
	int keyCounter;
	MemoryWrapper *memory;
	ClusterSelector *clusterSelector;

	Timer *timer;
	float lastThreshold;
};




#endif /* EVENTMEMORYTABLE_H_ */
